package com.hkts.management.cargolabel.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.cargolabel.entity.HktsCargoLabel;
import com.hkts.management.cargolabel.service.IHktsCargoLabelService;
import com.hkts.management.utils.CustomPageUtils;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author hml
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/order/hktsCargoLabel")
@Api(tags = "货物标签管理接口")
public class HktsCargoLabelController {
    private final Logger logger = LoggerFactory.getLogger(HktsCargoLabelController.class);

    @Autowired
    public IHktsCargoLabelService iHktsCargoLabelService;

    /**
     * 分页查询数据
     *
     * @param page           分页信息
     * @param hktsCargoLabel 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsCargoLabelPageList")
    public Result<Object> getHontUserList(Page<HktsCargoLabel> page, HktsCargoLabel hktsCargoLabel) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsCargoLabelService.selectPage(page, hktsCargoLabel)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsCargoLabel 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoLabelSave")
    public Result<Object> hktsCargoLabelSave(HktsCargoLabel hktsCargoLabel) {
        iHktsCargoLabelService.saveOrUpdate(hktsCargoLabel);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsCargoLabelGetById")
    public Result<Object> hktsCargoLabelGetById(String id) {
        HktsCargoLabel byId = iHktsCargoLabelService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoLabelDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsCargoLabelService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoLabelBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsCargoLabelService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

}
